
{% include "../header.html" %}
  <script src="/static/js/monaco-editor/min/vs/loader.js"></script>
  <style>
  .edit{
        min-height: 500px;
      border:1px solid grey;
    }
    .tt{
      text-align: center;
    }
    .layui-body{
      padding: 5px;
    }
    .art_title{
      max-width: 80%;
    }
    .art_type{
      width: 120px;
    }
    .layui-textarea{
      min-height:60px;
    }
            *::-webkit-scrollbar {
        width: 7px;
        height: 1px;
    }
*::-webkit-scrollbar-thumb {/*滚动条里面小方块*/
        border-radius: 7px;
        background: #1abc9c;
    }
*::-webkit-scrollbar-track {/*滚动条里面轨道*/
        border-radius: 7px;
        background: #EDEDED;
    }
  </style>
  <div class="layui-body">
    <div class="layui-form">
        <div class="layui-form-item art_title">
              <input type="text" name="title" required  lay-verify="required" placeholder="请输入标题" autocomplete="off" class="layui-input" value="{{art.title}}">
          </div>
        <div class="layui-form-item art_desc">
              <input type="text" name="desc" required  lay-verify="required" placeholder="请输入介绍" autocomplete="off" class="layui-input" value="{{art.desc}}">
          </div>
        <div class="layui-form-item art_keyword">
              <input type="text" name="keyword" required  lay-verify="required" placeholder="请输入关键词" autocomplete="off" class="layui-input" value="{{art.keyword}}">
          </div>
          <div class="layui-form-item art_type" value="{{art.tid}}">
              <select name="city" lay-verify="">
                  {% for nav in navs %}
                        {% if nav.type == 1 %}
                    <option value="{{nav.id}}"
                    {% if nav.id == art.tid%}
                            selected="selected"
                            {% end %}
                    >{{ escape(nav.name) }}</option>
                        {% end %}
                  {% end %}

                </select> 
          </div>
        <div class=" layui-form-item edit" value="{{art.content}}">

        </div>
    </div> 
    <button class="layui-btn layui-btn-fluid pub_article">博客发布</button>

  </div>
  <script>
    //初始化
   //初始化
    var editor;
    require.config({ paths: { 'vs': '/static/js/monaco-editor/min/vs' }});
	require(['vs/editor/editor.main'], function() {
		 editor = monaco.editor.create(document.querySelector('.edit'), {
			value:document.querySelector(".edit").attributes.value.value,
			language: 'markdown'
		});
	});

var form = layui.form
  form.render();
  //取值
  let type=document.querySelector(".art_title input").value
  form.on('select', function (data) {
    categoryName = data.elem[data.elem.selectedIndex];
    type=categoryName.value
  });

  //save
  function save () {
      let content = editor.getValue();
      let title = document.querySelector(".art_title input").value
      typed = document.querySelector(".art_type").attributes.value.value
      if(!isNaN(type)){
          return type
      }
      return typed
  }

  $(".pub_article").click(function(){

    $.post("",
    {
        id:"{{art.id}}",
      title:$(".art_title input").val(),
      desc:$(".art_desc input").val(),
      keyword:$(".art_keyword input").val(),
      content:editor.getValue(),
        type:save()
    },
    function(data,status){
    data = JSON.parse(data)
       if(data.code === 1){
          document.location.href="/art/"+data.obj
       }
       if(data.code === 0){
            layer.msg(data.message)
       }
    });
  });
  </script>
 {% include "../footer.html" %}